using Microsoft.Extensions.Options;

namespace SeataNet.Core.Configuration
{
    /// <summary>
    /// SeataNet配置验证器
    /// </summary>
    public class SeataNetConfigurationValidator : IValidateOptions<SeataNetConfiguration>
    {
        public ValidateOptionsResult Validate(string? name, SeataNetConfiguration options)
        {
            if (string.IsNullOrWhiteSpace(options.ApplicationId))
            {
                return ValidateOptionsResult.Fail("ApplicationId不能为空");
            }

            return ValidateOptionsResult.Success;
        }
    }

    /// <summary>
    /// AT模式配置验证器
    /// </summary>
    public class AtConfigurationValidator : IValidateOptions<AtConfiguration>
    {
        public ValidateOptionsResult Validate(string? name, AtConfiguration options)
        {
            return ValidateOptionsResult.Success;
        }
    }

    /// <summary>
    /// RPC配置验证器
    /// </summary>
    public class RpcConfigurationValidator : IValidateOptions<RpcConfiguration>
    {
        public ValidateOptionsResult Validate(string? name, RpcConfiguration options)
        {
            if (string.IsNullOrWhiteSpace(options.ServerAddress))
            {
                return ValidateOptionsResult.Fail("ServerAddress不能为空");
            }

            return ValidateOptionsResult.Success;
        }
    }
}
